'''
Created on Nov 30, 2010

@author: oabalbin
'''

import subprocess

def fixmateInformation(indexed_bam_file, use_mem, path_to_picard, temp_dir):
    '''
    '''
    picard_command=path_to_picard+'FixMateInformation.jar'
    use_temp_dir='-Djava.io.tmpdir='+temp_dir
    outfile=indexed_bam_file.replace('.bam','.fixMate.bam')
    maxinram=200000
    args = ['java','-Xmx'+str(use_mem)+'g', use_temp_dir,'-jar',picard_command,
            'I='+indexed_bam_file,'SO=coordinates', 'VALIDATION_STRINGENCY=SILENT',
            'O='+outfile,'-maxInRam',str(maxinram)
            ] 
    
    retcode = subprocess.call(args)
    
    return outfile

def markDuplicates(indexed_bam_file, use_mem, path_to_picard):
    '''
    '''
    picard_command=path_to_picard+'MarkDuplicates.jar'
    outfile=indexed_bam_file.replace('.bam','.markdup.bam')
    metrics_file=indexed_bam_file.replace('.bam','duplicates.stats')
    
    args=['java','-Xmx'+str(use_mem)+'g',picard_command, 
          'I='+indexed_bam_file, 'O='+outfile, 'METRICS_FILE='+metrics_file,
          'ASSUME_SORTED=true'
          ]

    retcode = subprocess.call(args)
    
    return outfile
